requirejs.config({
    baseUrl: './script/mdm',
    urlArgs: "bust=" + (new Date()).getTime(),
    paths:{
        // jquery: "../lib/jquery-1.8.3",
        juicer: "../lib/juicer"
    },
    shim:{
        'juicer': {
            exports: 'juicer'
        }
    }
});

// require(['device','user'],function(){});
require(['./common/common','menu'],function(common, menu){ menu.initMenu();});


var ajaxList = {};
//全局设置AJAX
$.ajaxSetup({
    cache: false,
    beforeSend: function (xhr) {
        var index = this.url.indexOf("_="), url = this.url || "", returnStatus = true;
        if (index > -1){
            url = this.url.substr(0, index);
        }
        if (ajaxList[url]) {
            var lastXhr = ajaxList[url];
            if (lastXhr.readyState <= 4) {
                returnStatus = false;
            }
        } else {
            ajaxList[url] = xhr;
        }
        return returnStatus;
    },
    success: function (data, textStatus, jqXHR) {
        if (!(data)) {
            // 获取后台数据异常，请检查后台服务
            alert("获取后台数据异常，请检查后台服务");
            // $m.comm.modal.alertModal("<p>暂时未获取数据，请重试！</p>", {backdrop: "static"});
            return;
        }
    },
    complete: function (xhr, textStatus) {
        var state = true;
        //IE9以下的浏览器，在上传文件后返回的状态码不标准。下面针对IE9以下的浏览器做了一些兼容处理
        //xhr.aborted属性在IE9以下的浏览器才会出现
        if (xhr.aborted || xhr.aborted == 0) {
            state = xhr.readyState == undefined && xhr.status == 0;
        } else {
            state = xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 201);
        }
        if (state) {
            this.url = this.url || "";
            var index = this.url.indexOf("_="), url = this.url;
            if (index > -1){
                url = this.url.substr(0, index);
            }
            delete ajaxList[url];

            //判断session超时
            var sessionstatus = xhr.getResponseHeader && xhr.getResponseHeader("sessionstatus");
            if (sessionstatus == "timeout") {
                // $m.comm.modal.alertModal("<p>" + commonPromptTimeout + "</p>", {fnHidden: function () {
                //     window.location.replace(CTX_PATH + "/admin/login.do");
                // }});
                alert("登录超时，请检查后台服务");
            }
        } else {
            // 系统异常
            // $m.comm.modal.alertModal("<p>暂时未获取数据，请重试！</p>", {backdrop: "static"});
            alert("系统异常，请检查后台服务");
        }
    }
});